<?php

use yii\db\Migration;

/**
 * Handles adding columns to table `{{%contract}}`.
 * Has foreign keys to the tables:
 *
 * - `{{%donor}}`
 */
class m221109_122953_add_id_donor_column_to_contract_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->addColumn('{{%contract}}', 'id_donor', $this->integer());

        // creates index for column `id_donor`
        $this->createIndex(
            '{{%idx-contract-id_donor}}',
            '{{%contract}}',
            'id_donor'
        );

        // add foreign key for table `{{%donor}}`
        $this->addForeignKey(
            '{{%fk-contract-id_donor}}',
            '{{%contract}}',
            'id_donor',
            '{{%donor}}',
            'id',
            'CASCADE'
        );
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        // drops foreign key for table `{{%donor}}`
        $this->dropForeignKey(
            '{{%fk-contract-id_donor}}',
            '{{%contract}}'
        );

        // drops index for column `id_donor`
        $this->dropIndex(
            '{{%idx-contract-id_donor}}',
            '{{%contract}}'
        );

        $this->dropColumn('{{%contract}}', 'id_donor');
    }
}
